package at.socialconference.web.client.util;

import java.util.Map;
import java.util.TreeMap;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ListBox;

public class AsyncCallbackGetCountries implements AsyncCallback<TreeMap<Integer, String>> {

	private ListBox listBox;

	public AsyncCallbackGetCountries(ListBox listBox) {
		this.listBox = listBox;
	}

	public void onFailure(Throwable caught) {
		listBox.addItem("Error fetching countries", "1");
	}

	public void onSuccess(TreeMap<Integer, String> result) {
		for (Map.Entry<Integer, String> country : result.entrySet()) {
			listBox.addItem(country.getValue(), country.getKey().toString());
		}
	}

}